﻿/// <reference path="../game/fourkill.util.js" />
/// <reference path="../input/init.fourkill.input.base.js" />
/// <reference path="../input/fourkill.input.gps.js" />
/// <reference path="../input/post.fourkill.input.singletons.js" />

var GpsTestsView_Gps = Base.extend({
    initialize: function initialize() {
        this.latitude = 0;
        this.longitude = 0;
        this.updateCount = 0;
        this.enabled = false;
    },
    isAvailable: function isAvailable() {
        return true;
    },
    enable: function enable() {
        if (!this.enabled && GlobalInputHandlers.Gps.isAvailable() && GlobalInputHandlers.Gps.enabled) {
            this.enabled = true;
            var self = this;
            GlobalInputHandlers.Gps.subscribe("GpsTestsView.Gps", self);
        }
    },
    disable: function disable() {
        if (this.enabled) {
            this.enabled = false;
            GlobalInputHandlers.Gps.unsubscribe("GpsTestsView.Gps");
        }
    },
    fireEvent: function fireEvent(eventName, data) {
        if (eventName == "gps") {
            this.latitude = data.latitude;
            this.longitude = data.longitude;
            this.updateCount++;
            if (data.prevent) data.preventDefault();
        }
    },
    update: function update(context) {
        context.latitude = this.latitude;
        context.longitude = this.longitude;
    }
});
